import cn.hutool.core.date.DateUtil;
import cn.org.rapid_framework.generator.GeneratorFacade;
import cn.org.rapid_framework.generator.GeneratorProperties;

public class GeneratorMain {

	public static void main(String[] args) throws Exception {
		String outDir = "D:\\code_out";
		String author = "xuhaowen";
		String basePackage = "cn.yanpin.bgc";
		String[] tables = new String[]{"order_pay", "goods_style"};
		genCode(outDir, author, basePackage, tables);

		// 查询 表名
		// SELECT GROUP_CONCAT(CONCAT('"', table_Name, '"') SEPARATOR ', ') FROM Information_schema.`TABLES` WHERE table_schema = 'db_name';
	}

	/**
	 * 生成代码
	 * @param outDir
	 * @param author
	 * @throws Exception
	 */
	public static void genCode(String outDir, String author, String basePackage, String ... tables) throws Exception {
		GeneratorFacade generatorFacade = new GeneratorFacade();
		generatorFacade.getGenerator().addTemplateRootDir("classpath:template"); //模板路径
		generatorFacade.getGenerator().setOutRootDir(outDir);

		GeneratorProperties.setProperty("author", author);//作者
		GeneratorProperties.setProperty("createTime", DateUtil.today());
		GeneratorProperties.setProperty("packageNamePrefix", basePackage); //包名前缀
		//需要移除的表名前缀,使用逗号进行分隔多个前缀,示例值: t_,v_
		GeneratorProperties.setProperty("tableRemovePrefixes", "");
		//删除
		generatorFacade.deleteOutRootDir();
		//生成
		generatorFacade.generateByTable(tables);
	}


}
